/*
gfileutils.cpp
18/05/2014
psycommando@gmail.com

Description:
File with some handy tools for working with files.
Is as portable and simple as possible.

No crappyrights. All wrongs reversed!
*/
#include "gfileutils.h"
#include <sstream>
#include <iostream>
using std::string;
using  std::cout;
using std::endl;
using std::stringstream;

namespace g { namespace fileutils {


	bool has_suffix(const std::string &str, const std::string &suffix)
	{
		return str.size() >= suffix.size() &&
				str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
	}

	void CreateDir( const string & path )
	{
		stringstream sstrmkdir;
		sstrmkdir <<"mkdir \"" << path <<"\"";
		system( sstrmkdir.str().c_str() );
		cout << endl;
	}

	string GetPathOnly( const string & fullpath )
	{
		return fullpath.substr( 0, fullpath.find_last_of("\\/") );
	}

	string GetFilenameFromPath( const string & fullpath )
	{
        string::size_type poslastslash = fullpath.find_last_of("\\/");
        return fullpath.substr( poslastslash + 1, fullpath.size() - poslastslash  );
	}

	string GetPathWithoutFileExt( const string & fullpath )
	{
		return fullpath.substr( 0, fullpath.find_last_of(".") );
	}

}; };